package com.itheima.dubbo.service.impl;

import com.itheima.dubbo.HelloFaceService;
import com.itheima.dubbo.WhatFaceService;
import com.itheima.pojo.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;

/**
 * @author by jojo
 * @Date 2022/3/25
 * @Description
 */
@DubboService(version = "2.0.0",timeout = 3000,retries = 1)
public class HelloFaceServiceImpl2 implements HelloFaceService {

    @DubboReference
    private WhatFaceService whatFaceService;
    @Override
    public String hello(String name) {
        String xx="killqueen...v2...";
        // 本端是否为提供端，这里会返回true
//        boolean consumerSide = RpcContext.getContext().isProviderSide();
//        System.out.println("consumerSide = " + consumerSide);
//        // 获取调用方IP地址
//        String remoteHost = RpcContext.getContext().getRemoteHost();
//        System.out.println("remoteHost = " + remoteHost);
////         获取当前服务配置信息，所有配置信息都将转换为URL的参数
//        String application = RpcContext.getContext().getUrl().getParameter("application");
//        System.out.println("application = " + application);
////         注意：每发起RPC调用，上下文状态会变化
//        whatFaceService.what();
//        //  此时本端变成消费端，这里会返回false
//        boolean providerSide = RpcContext.getContext().isProviderSide();
//        System.out.println("providerSide = " + providerSide);
        String jojo = RpcContext.getContext().getAttachment("jojo");
        System.out.println("jojo = " + jojo+"----"+xx);
        return "hello,killqueen,name:"+name;
    }

    @Override
    public User byUser() {
        User user = new User();
        user.setName("killerQueen");
        user.setAge(18);
        return user;
    }
}
